package com.crazyauntzhang.easyshopbackend.dao;

import com.crazyauntzhang.easyshopbackend.domain.TurnoverFlow;
import com.crazyauntzhang.easyshopbackend.result.FindTurnoverResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
@Repository
public interface TurnoverFlowDao {

	/**
	 * 插入流水数据
	 *
	 * @param sequenceNo       流水号
	 * @param sequenceDateTime 流水时间
	 * @param userID           收银员ID
	 * @param itemBarcode      商品条码
	 * @param price            商品单价
	 * @param quantity         购买数量
	 * @param profit           单品收益
	 */
	void insertFlow(@Param("sequenceNo") String sequenceNo,
					@Param("sequenceDateTime") LocalDateTime sequenceDateTime,
					@Param("userID") String userID,
					@Param("itemBarcode") String itemBarcode,
					@Param("operation") Integer operation,
					@Param("price") Double price,
					@Param("quantity") Double quantity,
					@Param("profit") Double profit,
					@Param("handlerID") String handlerID,
					@Param("purchaseNo") String purchaseNo);

	List<TurnoverFlow> selectFlow(@Param("sequenceNo") String sequenceNo);

	TurnoverFlow selectFlowWithItemBarcode(@Param("sequenceNo") String sequenceNo,
										   @Param("itemBarcode") String itemBarcode);

	Double selectSalesIn30Days(@Param("itemBarcode") String itemBarcode);

	List<String> selectTop20SalesIn30DaysWithBarcode();

	List<FindTurnoverResponse> selectTodayTurnover();

	List<FindTurnoverResponse> selectPeriodTurnover(@Param("beginDate") LocalDate beginDate,
													@Param("endDate") LocalDate endDate);

	Double selectRestQuantity(@Param("sequenceNo") String sequenceNo,
							  @Param("itemBarcode") String itemBarcode);

}
